<template>
  <div class="address">
    <div class="box">
      <div class="site" v-for="(item,index) in list" :key='index'>
        <div class="d-f">

          <span class="span" v-show="item.user_id>0" >默认</span>
          <div  v-show="item.user_id<=0" @click="setmoren(index)"  class="noselecrbox"></div>

          <div class="site-l" @click="selectcurrent(index)">
            <p class="p1"> {{item.address}}</p>
            <p class="p2">{{item.consignee}}   {{item.mobile}}</p>
          </div>
        </div>
        <div class="site-r" @click="toedit(item)">
          <img src="../../assets/img/mine/bianji.png"/>
        </div>
      </div>
     
    </div>
    <div class="xin-address" @click="xinaddress">新建收货地址</div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        list:'',
        cart_id:"",
        good_id:''
      }
    },
    methods: {
      // 跳转新地址
      xinaddress(){
        if(!localStorage.getItem('cart_id')){
          localStorage.setItem("cart_id",this.cart_id)
        }
        if(!localStorage.getItem('good_id')){
          localStorage.setItem("good_id",this.good_id)
        }
        this.$router.replace({path:'/xin-address',query: {path:'selectaddress'}})
      },
      getalllist(){
        var uid=localStorage.getItem('uid')
        this.$get(
            // method: "get",
            "api/gzh_order.php?action=address_list",
            {
              uid:uid,
              page:1,
              limit:30,
            },
        ).then(response => {
            this.list=response.data
        })
      },
      toedit(item){
          if(!localStorage.getItem('cart_id')){
            localStorage.setItem("cart_id",this.cart_id)
          }
          if(!localStorage.getItem('good_id')){
            localStorage.setItem("good_id",this.good_id)
          }
          this.$router.replace({
            path:'/editaddress',
            query: {id:item.address_id,path:'selectaddress'}
            }) 
      },
       setmoren(index){
        var uid=localStorage.getItem('uid')
        this.$get(
            // method: "get",
            "api/gzh_order.php?action=address_default",
            {
              uid:uid,
              address_id:this.list[index].address_id
            },
        ).then(response => {
            if(response.error==0){
              this.$toast('设置成功');
              this.getalllist()
            }
        })
      },
      selectcurrent(index){
        localStorage.setItem("selectitem",this.$qs.stringify(this.list[index]))

        if(!localStorage.getItem('cart_id')){
          localStorage.setItem("cart_id",this.cart_id)
        }
        if(!localStorage.getItem('good_id')){
          localStorage.setItem("good_id",this.good_id)
        }

        // console.log(localStorage.getItem('cart_id'))
        console.log(localStorage.getItem('cart_id')!='undefined')
        if(localStorage.getItem('cart_id')!='undefined'){
          console.log(localStorage.getItem('cart_id').split(','))
          this.$router.replace({path:'/gojiesuan',query:{'cart_id': localStorage.getItem('cart_id').split(',')}})
          

        }else if(localStorage.getItem('good_id')!='undefined'){

          this.$router.replace({path:'/jifenjiesuan',query:{'good_id': localStorage.getItem('good_id').split(',')}})
        }
      }
    },
    created () {
      this.getalllist()

      this.cart_id=this.$route.query.cart_id

      this.good_id=this.$route.query.good_id
      // console.log(cart_id,111111111111111111)
      
    }
  }
 
</script>

<style scoped>
.noselecrbox {
  /* margin-right: 20px; */
  width: 28px;
  height: 28px;
  border: 1PX solid #666;
  border-radius: 50%;
  margin: 0 26px;
  box-sizing: border-box;
}
.d-f{
  display: flex;
  align-items: center;
}
.address{
  width: 100vw;
}
.box{
  width: 100%;
  height: 80vh;
  overflow: hidden;
  overflow-y:scroll;
  border-top: 1px solid #EAEAEA;
}
.site{
  width:693px;
  height: 173px;
  border-bottom: 1px solid #EEEEEE;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.site-l .p1{
  font-size:30px;
  font-family:PingFang SC;
  font-weight:500;
  color:rgba(51,51,51,1);
  line-height:30px;
}
.span{
  display: inline-block;
  width: 60px;
  height: 30px;
  font-size: 26px;
  background: red;
  color: #fff;
  font-family:PingFang SC;
  font-weight:500;
  border-radius: 10px;
  text-align: center;
  line-height: 30px;
  margin-right:20px;
}
.site-l .p2{
  font-size:28px;
  font-family:PingFang SC;
  font-weight:500;
  color:rgba(102,102,102,1);
  line-height:30px;
  margin-top: 31px;
}
.site-r img{
  width:29px;
  height:29px;
}

.xin-address{
  width:632px;
  height:100px;
  border-radius:50px;
  background: #18B869;
  font-size:34px;
  font-family:PingFang SC;
  font-weight:bold;
  color:rgba(255,255,255,1);
  line-height:100px;
  text-align: center;
  line-height: 100px;
  position: fixed;
  bottom: 93px;
  left: 59px;
}
</style>